home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1095 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  63 lines

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How do you pass along a variable argument list?
  5. Date: Thu, 11 Jan 1996 12:38:07 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d30nv$k8r@tahko.lpr.carel.fi>
  8. References: <4d1i8v$k8h@news.mcl.bdm.com>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. ywu@plato.sky.bdm.com wrote:
  13.  
  14. >Hi, there:
  15.  
  16. >I am writing a wrapper around a routine which takes variable argument list only. I  
  17. >want my wrapper has the similar prototype and can pass the variable arguments  
  18. >directly to the routine(by the way, I cannot change the code of that routine).
  19.  
  20. >I guess it is really hard to do it in ANSI, and I know how to do it in a stupid  
  21. >way---but, is there any way around??
  22.  
  23. >Thanks!!
  24.  
  25. >Yibing Wu
  26. >ywu@plato.sky.bdm.com
  27.  
  28. Actually, it's not so difficult. Here's an ANSI-compliant example that
  29. wraps the printf function:
  30.  
  31. #include    <stdio.h>
  32. #include    <stdarg.h>
  33.  
  34. void    MyPrintf(char *fmt, ...)
  35. {
  36.     va_list    argp;
  37.  
  38.     va_start(argp, fmt);
  39.     printf(fmt, argp);
  40.     va_end(argp);
  41. }
  42.  
  43. An Unix-like version goes like this:
  44.  
  45. #include    <stdio.h>
  46. #include    <varargs.h>
  47.  
  48. void    MyPrintf(va_alist)
  49. va_dlc            /* Observ there's no semicolon here */
  50. {
  51.     va_list    argp;
  52.  
  53.     va_start(argp);
  54.     printf(argp);
  55.     va_end(argp);
  56. }
  57.  
  58. HTH,
  59.  Ari Lukumies
  60.  
  61. All my opinions are mine and mine alone.
  62.  
  63.